define(['../../../../../js/lib/other/sweet-alert'],function() {
    return ['$scope','$location', '$interval','$timeout','$routeParams','bizProxy', function($scope,$location,$interval,$timeout,$routeParams,bizProxy) {
    	$scope.$emit("top-show",'true');//顶部显示
    	$scope.$emit('menuTypeLight','loan'); 	//控制底部menu高亮
    	$scope.$emit('bub-menu','true'); 	//隐藏底部menu
    	$scope.$emit('flag-tag','58'); 	//显示底部文字
    	
    	var questionLoanSurveyList = [
    	                             {
    	                                 "name": "企业类型",
    	                                 "index": 0,
    	                                 "info": [
    	                                     {
    	                                         "name": "国有企业",
    	                                         "val": 15,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "外资企业",
    	                                         "val": 12,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "内资企业",
    	                                         "val": 10,
    	                                         "slt": false
    	                                     }
    	                                 ]
    	                             },
    	                             {
    	                                 "name": "注册资本",
    	                                 "index": 1,
    	                                 "info": [
    	                                     {
    	                                         "name": "1000万以上",
    	                                         "val": 20,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "50万－1000万",
    	                                         "val": 15,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "10万-50万",
    	                                         "val": 10,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "10万以下",
    	                                         "val": 5,
    	                                         "slt": false
    	                                     }
    	                                 ]
    	                             },
    	                             {
    	                                 "name": "经营年限",
    	                                 "index": 2,
    	                                 "info": [
    	                                     {
    	                                         "name": "10年以上",
    	                                         "val": 5,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "5-10年",
    	                                         "val": 3,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "5年以下",
    	                                         "val": 2,
    	                                         "slt": false
    	                                     }
    	                                 ]
    	                             },
    	                             {
    	                                 "name": "上一年度净利润",
    	                                 "index": 3,
    	                                 "info": [
    	                                     {
    	                                         "name": "100万以上",
    	                                         "val": 15,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "10万－100万",
    	                                         "val": 10,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "10万以下或亏损",
    	                                         "val": 3,
    	                                         "slt": false
    	                                     }
    	                                 ]
    	                             },
    	                             {
    	                                 "name": "名下不动产情况",
    	                                 "index": 4,
    	                                 "info": [
    	                                     {
    	                                         "name": "工业地产或住宅房地产",
    	                                         "val": 15,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "办公楼",
    	                                         "val": 10,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "无资产",
    	                                         "val": 5,
    	                                         "slt": false
    	                                     }
    	                                 ]
    	                             },
    	                             {
    	                                 "name": "涉诉、被强制执行的记录 ",
    	                                 "index": 5,
    	                                 "info": [
    	                                     {
    	                                         "name": "无诉讼无执行",
    	                                         "val": 10,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "有诉讼未被执行",
    	                                         "val": 5,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "有被强制执行记录",
    	                                         "val": -20,
    	                                         "slt": false
    	                                     }
    	                                 ]
    	                             },
    	                             {
    	                                 "name": "案由",
    	                                 "index": 6,
    	                                 "info": [
    	                                     {
    	                                         "name": "经济合同纠纷",
    	                                         "val": 3,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "侵权纠纷",
    	                                         "val": 2,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "其他",
    	                                         "val": 1,
    	                                         "slt": false
    	                                     }
    	                                 ]
    	                             },
    	                             {
    	                                 "name": "证据充分程度",
    	                                 "index": 7,
    	                                 "info": [
    	                                     {
    	                                         "name": "80%以上胜诉",
    	                                         "val": 5,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "胜诉难料，有争议",
    	                                         "val": 3,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "胜诉希望较低 ",
    	                                         "val": 0,
    	                                         "slt": false
    	                                     }
    	                                 ]
    	                             },
    	                             {
    	                                 "name": "被告身份",
    	                                 "index": 8,
    	                                 "info": [
    	                                     {
    	                                         "name": "公务员，国企、事业单位或其职员",
    	                                         "val": 5,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "外资企业或其职员",
    	                                         "val": 3,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "内资企业或其职员",
    	                                         "val": 2,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "其他",
    	                                         "val": 0,
    	                                         "slt": false
    	                                     }
    	                                 ]
    	                             },
    	                             {
    	                                 "name": "被告财产线索",
    	                                 "index": 9,
    	                                 "info": [
    	                                     {
    	                                         "name": "有财产线索且易变现",
    	                                         "val": 5,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "有财产线索但难变现",
    	                                         "val": 3,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": " 无财产线索",
    	                                         "val": 0,
    	                                         "slt": false
    	                                     }
    	                                 ]
    	                             },
    	                             {
    	                                 "name": "案件受理法院",
    	                                 "index": 10,
    	                                 "info": [
    	                                     {
    	                                         "name": "一线城市或长三角地区",
    	                                         "val": 2,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "二线或省会城市",
    	                                         "val": 1,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "其他",
    	                                         "val": 0,
    	                                         "slt": false
    	                                     }
    	                                 ]
    	                             },
    	                             {
    	                                 "name": "当事人是否有提供足额担保物",
    	                                 "index": 11,
    	                                 "info": [
    	                                     {
    	                                         "name": "是",
    	                                         "val": 30,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "否",
    	                                         "val": 0,
    	                                         "slt": false
    	                                     }
    	                                 ]
    	                             },
    	                             {
    	                                 "name": "是否有赢火虫APP逾期还款记录",
    	                                 "index": 12,
    	                                 "info": [
    	                                     {
    	                                         "name": "是",
    	                                         "val": -20,
    	                                         "slt": false
    	                                     },
    	                                     {
    	                                         "name": "否",
    	                                         "val": 0,
    	                                         "slt": false
    	                                     }
    	                                 ]
    	                             }
    	                             
    	                         ];
    	
    	$scope.questionLoanSurveyList = questionLoanSurveyList;
    	
    	
    	
    	//点击选择答案
    	$scope.selectQuesition = function(num,index){
    		var partList = questionLoanSurveyList[num].info;
    		partList.forEach(function(e){
    			e.slt = false;
    		});
    		partList[index].slt = true;
    		$scope.questionLoanSurveyList = questionLoanSurveyList;
    	}
    	
    	//点击提交
    	$scope.subExamPaper = function(){
    		 var sweetData = {
   					title : "是否确认提交？",
   					text : "",
   					type : "",
   					showCancelButton : true,
   					closeOnConfirm : false
   				};
       			sweetAlert(sweetData,function(){
       				$timeout(function(){
       					//计算分数
       					calculateScore();
       				},500);
       			},function(){return;});
       			
       			var headerInfo = {},bizInfo = {};
       			 	 
    	}
    	
    	//计算分数
    	function calculateScore(){
    		var score = 0;
    		for(var i=0;i<questionLoanSurveyList.length;i++){
    			var tempList = questionLoanSurveyList[i].info;
    			for(var j=0;j<tempList.length;j++){
    				if(tempList[j].slt){
    					score += tempList[j].val;
    				}
    			}
    		}
    		if(checkLoanApplyData.isGuarntee === '0'){
    			score = score*1 + 30;
    		}
    		
    		checkAnswerData(score);
    		
    	}
    	
    	//处理题目和答案
    	function checkAnswerData(score){
    		var answerArray = new Array();
    		for(var i=0;i<questionLoanSurveyList.length;i++){
    			var tempList = questionLoanSurveyList[i].info;
    			var tempData = {"title":questionLoanSurveyList[i].name};
    			for(var j=0;j<tempList.length;j++){
    				if(tempList[j].slt){
    					tempData.answer = tempList[j].name;
    					break;
    				}else{
    					tempData.answer = "";
    				}
    			}
    			answerArray.push(tempData);
    		}
    		
    		transData.rcDetail = JSON.stringify(answerArray);
    		subSurveyData(score);
    	}
    	
    	
    	function subSurveyData(score){
	    	var headerInfo = {},bizInfo = {};
	    	headerInfo.pageNum = '';
	        headerInfo.pageSize = '';
	        headerInfo.sessionId = transData.sessionId;
	         
	        bizInfo.loanApplyId = checkLoanApplyData.loanApplyId;
	        bizInfo.rcScore = score;
	        bizInfo.rcDetail = transData.rcDetail;
	        bizInfo.isGuarntee = checkLoanApplyData.isGuarntee;
	        bizInfo.approveContent = checkLoanApplyData.approveContent
	        
	        
	        console.log(bizInfo);
	        $scope.$emit("loadingChange",true);
	        bizProxy.queryProxyBizData("approveLoan",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
    				   $scope.$emit("loadingChange",false);
                       if(score >= 50){
			    		    $timeout(function(){
			    		    	$scope.$emit("goNext","/agreeLoan");
								//	$scope.$emit("goNext","/");
							//		$location.path("/").replace();//想改变当前 URL 而不创建新的历史记录的话
							},0);	
			    			
			    		  }else{
			    		     FIREFLY("对不起，您未达到\"免息贷\"申请的标准！", "","",function(){
							   $timeout(function(){
			            	   //	history.back();
							   },0);
						  });
			    	    }
						
					   console.log(tempData);
		    		},function(data) {
						if (data != "") {//FAIL
							$scope.$emit("loadingChange", false);
							if (data.errorCode == ERROR_CODE.noLogin) {
								FIREFLY("", data.errorMsg, "", function () {
									//调用退出登录
									transData.mobileNo = "";
									transData.password = "";
									transData.sessionId = "";
									transData.userType = "";
									resultData.loginUserData = "";
									$timeout(function () {
										$scope.$emit("goNext", "/mine");
									}, 0);
								});
							} else {
								$scope.$emit("promptAlertMsg", data.errorMsg);
								$scope.$emit("showCollect", true);
								$timeout(function () {
									$scope.$emit("showCollect", false);
								}, transData.promptTime);
							}
						} else {
							$scope.$emit("loadingChange", false);
							$scope.$emit("promptAlertMsg", "连接超时");
							$scope.$emit("showCollect", true);
							$timeout(function () {
								$scope.$emit("showCollect", false);
							}, transData.promptTime);
						}

		    		});
          
    	}
    	
        	
        	
    $scope.$apply();
    }];
});